package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.flight.domain.FlightTicketaddressCRM;
import com.ktgj.flight.domain.FlightTicketaddressCRMVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightTicketaddress;
import com.ktgj.flight.service.IFlightTicketaddressService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机票预订_取票点Controller
 * 
 * @author ruoyi
 * @date 2022-01-10
 */
@RestController
@RequestMapping("/ticketaddress")
public class FlightTicketaddressController extends BaseController
{
    @Autowired
    private IFlightTicketaddressService flightTicketaddressService;

    /**
     * 查询机票预订_取票点列表
     */
    //@PreAuthorize(hasPermi = "flight:ticketaddress:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightTicketaddress flightTicketaddress)
    {
        startPage();
        List<FlightTicketaddress> list = flightTicketaddressService.selectFlightTicketaddressList(flightTicketaddress);
        return getDataTable(list);
    }

    /**
     * 导出机票预订_取票点列表
     */
    @PreAuthorize(hasPermi = "flight:ticketaddress:export")
    @Log(title = "机票预订_取票点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightTicketaddress flightTicketaddress) throws IOException
    {
        List<FlightTicketaddress> list = flightTicketaddressService.selectFlightTicketaddressList(flightTicketaddress);
        ExcelUtil<FlightTicketaddress> util = new ExcelUtil<FlightTicketaddress>(FlightTicketaddress.class);
        util.exportExcel(response, list, "机票预订_取票点数据");
    }

    /**
     * 获取机票预订_取票点详细信息
     */
    @PreAuthorize(hasPermi = "flight:ticketaddress:query")
    @GetMapping(value = "/{addressId}")
    public AjaxResult getInfo(@PathVariable("addressId") Long addressId)
    {
        return AjaxResult.success(flightTicketaddressService.selectFlightTicketaddressById(addressId));
    }

    /**
     * 新增机票预订_取票点
     */
    @PreAuthorize(hasPermi = "flight:ticketaddress:add")
    @Log(title = "机票预订_取票点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightTicketaddress flightTicketaddress)
    {
        return toAjax(flightTicketaddressService.insertFlightTicketaddress(flightTicketaddress));
    }

    /**
     * 修改机票预订_取票点
     */
    @PreAuthorize(hasPermi = "flight:ticketaddress:edit")
    @Log(title = "机票预订_取票点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightTicketaddress flightTicketaddress)
    {
        return toAjax(flightTicketaddressService.updateFlightTicketaddress(flightTicketaddress));
    }

    /**
     * 删除机票预订_取票点
     */
    @PreAuthorize(hasPermi = "flight:ticketaddress:remove")
    @Log(title = "机票预订_取票点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{addressIds}")
    public AjaxResult remove(@PathVariable Long[] addressIds)
    {
        return toAjax(flightTicketaddressService.deleteFlightTicketaddressByIds(addressIds));
    }

    /**
     * 配送方式-机场取票
     * @param flightTicketaddress
     * @return
     */
    @PostMapping("/flightTicketList")
    public AjaxResult flightTicketList(@RequestBody FlightTicketaddressCRMVO flightTicketaddress) {
        List<FlightTicketaddressCRM> ticketList = flightTicketaddressService.flightTicketList(flightTicketaddress.getAirportId(), flightTicketaddress.getOrgAirportId());
        if (ticketList != null && ticketList.size() > 0) {
            return AjaxResult.success(ticketList);
        } else {
            return AjaxResult.error("未查询到取票地点！");
        }
    }
}
